package b3.widget.home.unlock
{
	import as3isolib.geom.Pt;
	
	import b3.config.*;
	import b3.scene.home.*;
	import b3.util.*;
	import b3.widget.basic.*;
	import b3.widget.guide.*;
	
	import com.greensock.*;
	
	import flash.events.*;

	public class UnlockSectionMovie extends BasicWidget
	{
		private var sectionIndex:int;
		
		public function UnlockSectionMovie(sectionIndex:int)
		{
			super();
			this.sectionIndex = sectionIndex;
			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			var town:Town = HomeScene.getInstance().getCurrentTown(); 
			town.setViewCenter(new Pt(SectionConfig.viewCenterX[sectionIndex], SectionConfig.viewCenterY[sectionIndex], 0));
			TweenLite.delayedCall(2, town.removeLocks, [sectionIndex]); 
			TweenLite.delayedCall(4, showNpcDialog);
		}
		
		private function showNpcDialog():void
		{
			var sectionConfig:SectionConfig = Config.townConfigs[0].sectionConfigs[sectionIndex];
			var npcDialog:NpcDialog = new NpcDialog("NpcSecretary1", sectionConfig.unlockPrompt);
			addChild(npcDialog);
			npcDialog.addEventListener(Event.REMOVED_FROM_STAGE, onNpcDialogRemoved);
		}
		
		private function onNpcDialogRemoved(event:Event):void
		{
			TweenLite.delayedCall(0.1, close);
		}
		
	}
}